package jok.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileOutputStreamDemo {

	public static void main(String[] args) {

		writeFile();

		FileDemo.deleteFile("D:\\a.txt");
	}

	public static void writeFile() {
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(new File("D:/a.txt"));
			String str = "HelloWorld";
			byte[] bs = str.getBytes();
			for (byte b : bs) {
				fos.write(b);// 写单个字节
			}
			fos.write(bs);// 写字节数组
			fos.write(bs, 2, 4);// 写字节数组指定索引
			fos.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fos != null)
					fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
